#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
int N;
vector<int> G[maxn];
ll f[maxn], d[maxn], s[maxn];

int dfs(int u, int fa){
    f[u] = 1;

    for(int v:G[u])if(v!=fa){
        f[u] += dfs(v, u);
    }
    return f[u];
}

ll dfsd(int u, int fa){
    if(u!=fa) d[u] = d[fa]+1;
    ll t = d[u];
    for(int v:G[u])if(v!=fa){
            t += dfsd(v, u);
        }
    return t;
}

void dp(int u, int fa){
    for(int v:G[u])if(v!=fa){
        s[v] = s[u] + N - f[v] - f[v];
        dp(v, u);
        }
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    memset(s, -1, sizeof d);
    cin >> N;
    int r = 0;
    for (int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b;
        if(!r) r = a;
        G[a].push_back(b), G[b].push_back(a);
    }
    dfs(r, r);
    s[r] = dfsd(r, r);
    dp(r, r);
    ll ans = LLONG_MAX;
    for (int i = 0; i < maxn; ++i) {
        if(s[i]!=-1) ans = min(ans, s[i]);
    }
    cout << ans;
    return 0;
}
/**
9
1 2
1 3
1 4
1 5
5 6
6 7
6 8
6 9
 **/